home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-04-02 | 23.6 KB | 848 lines | [TEXT/MPS ] |
- { UOffscreenManager.inc1.p}
- { Copyright © 1990 by Apple Computer, Inc. All rights reserved.}
-
- { Change List:
-
- ddmmyy
- GAP 070990 Eliminated unsafe use of an object field as a var or > 4 byte parameter
- error in TOffscreenManager.Draw>DrawEach.
- GAP 070990 Eliminated unsafe use of an object field as a var or > 4 byte parameter
- error in TOffscreenManager.CopyBitsFrom>CopyEach.
- GAP 070990 Eliminated unsafe use of an object field as a var or > 4 byte parameter
- error in TOffscreenManager.CopyBitsFromScreen>CopyEach.
- GAP 070990 Eliminated unsafe use of an object field as a var or > 4 byte parameter
- error in TOffscreenManager.CopyBitsTo>CopyEach.
- GAP 070990 Eliminated unsafe use of an object field as a var or > 4 byte parameter
- error in TOffscreenManager.CopyBitsToScreen>CopyEach.
- GAP 070990 Eliminated 2 unsafe use of an object field as a var or > 4 byte parameter
- errors in TOffscreenDevice.Draw.
- GAP 070990 Eliminated unsafe use of an object field as a var or > 4 byte parameter
- error in TOffscreenDevice.CopyBitsFrom.
- GAP 070990 Eliminated 4 unsafe use of an object field as a var or > 4 byte parameter
- errors in TOffscreenDevice.CopyBitsFromScreen.
- GAP 070990 Eliminated 2 unsafe use of an object field as a var or > 4 byte parameter
- errors in TOffscreenDevice.CopyBitsToScreen.
- GAP 191290 Added comments, cleaned up formatting, removed previous "GAP" comments.
- GAP 250191 Removed superfluous comments.
- GAP 250191 Added private cohandler class TDepthAndColorChecker.
- GAP 250191 Added code to TOffscreenManager- IOffscreenManager, Free, Fields to
- handle fDepthAndColorChecker instance variable.
- GAP 250191 Got rid of, now obslolete, TOffscreenManager.Update.
- GAP 250191 Changed TOffscreenDevice.CheckDepthAndColor so warning
- concerning failure of ReallocOSImage is only written if
- we actually try to Realloc.
- GAP 060291 Added code to TOffscreenDevice.CheckDepthAndColor to adjust coordinate
- system of the TOffscreenDevice so it is updated in the context of its
- on-screen graphics device.
- GAP 080391 Put GetOSGrafEnv/SetOSGrafEnv/SetGrafEnv in TOffscreenDevice.CheckDepthAndColor.
- GAP 010491 Some reformatting.
-
- End Change List. }
-
- TYPE
-
- { TDepthAndColorChecker is a cohandler that checks and, if necessary, adjusts
- offscreen devices for depth and color table changes every 1/2 second. }
-
- TDepthAndColorChecker = OBJECT(TEvtHandler)
-
- fOffscreenManager: TOffscreenManager;
-
- PROCEDURE TDepthAndColorChecker.IDepthAndColorChecker (anOffscreenManager: TOffscreenManager);
-
- PROCEDURE TDepthAndColorChecker.Fields (PROCEDURE DoToField (fieldName: Str255;
- fieldAddr: Ptr;
- fieldType: INTEGER));
- OVERRIDE;
-
- FUNCTION TDepthAndColorChecker.DoIdle(phase: IdlePhase): BOOLEAN;
- OVERRIDE;
-
- END; {TDepthAndColorChecker}
-
-
- { A TOffscreenDevice represents an offscreen image for every graphics
- device (monitor) in the user's system. }
-
- TOffscreenDevice = OBJECT(TOSImage)
-
- fParentDevice: GDHandle; { The graphics device. }
- fDeviceRect: Rect; { The rectangle encompassing the device's screen coordinates. }
- fClipRect: Rect; { The rectangle representing the area actually used on this OSImage. }
-
- PROCEDURE TOffscreenDevice.IOffscreenDevice (gp: GrafPtr;
- size: Point;
- aScreenDevice: GDHandle);
-
- PROCEDURE TOffscreenDevice.Fields (PROCEDURE DoToField (fieldName: Str255;
- fieldAddr: Ptr;
- fieldType: INTEGER));
- OVERRIDE;
-
- PROCEDURE TOffscreenDevice.CheckDepthAndColor;
-
- PROCEDURE TOffscreenDevice.Draw (PROCEDURE QuickDrawStuff; drawRect: Rect);
-
- PROCEDURE TOffscreenDevice.CopyBitsFrom (srcBits: BitMap;
- srcRect: Rect;
- offscreenRect: Rect;
- mode: INTEGER;
- maskRgn: RgnHandle);
-
- PROCEDURE TOffscreenDevice.CopyBitsFromScreen (screenRect: Rect;
- mode: INTEGER;
- maskRgn: RgnHandle);
-
- PROCEDURE TOffscreenDevice.CopyBitsTo (dstBits: BitMap;
- dstRect: Rect;
- offscreenRect: Rect;
- mode: INTEGER;
- maskRgn: RgnHandle);
-
- PROCEDURE TOffscreenDevice.CopyBitsToScreen (screenRect: Rect;
- mode: INTEGER;
- maskRgn: RgnHandle);
-
- END; {TOffscreenDevice}
-
-
- { Data structure representing a 2-D transformation. }
-
- TransformRect = RECORD
- CASE INTEGER OF
- 0: (
- offsetV: INTEGER;
- offsetH: INTEGER;
- scaleV: INTEGER;
- scaleH: INTEGER
- );
-
- 1: (
- offset: Point;
- scale: Point
- );
- END;
-
-
- { CalculateTransform will calculate a TransformRect (with translation and scaling)
- that will ransform the 'target' rectangle to the 'std' rectangle when the
- Transform procedure is used. }
-
- PROCEDURE CalculateTransform (target, std: Rect;
- VAR transform: TransformRect);
-
- VAR
-
- targetDeltaH, targetDeltaV: INTEGER;
- stdDeltaH, stdDeltaV: INTEGER;
-
- BEGIN {CalculateTransform}
- targetDeltaH := target.right - target.left;
- targetDeltaV := target.bottom - target.top;
- stdDeltaH := std.right - std.left;
- stdDeltaV := std.bottom - std.top;
-
- transform.scaleH := stdDeltaH DIV targetDeltaH;
- transform.scaleV := stdDeltaV DIV targetDeltaV;
- transform.offsetH := std.left - target.left;
- transform.offsetV := std.top - target.top
- END; {CalculateTransform}
-
-
- { Transform will apply the transform in the TransformRect, 'using', to the 'fromRect'
- to produce the 'toRect'. That is, T(fromRect) = toRect. }
-
- PROCEDURE Transform (fromRect: Rect;
- using: TransformRect;
- VAR toRect: Rect);
-
- BEGIN {Transform}
- toRect.left := (fromRect.left + using.offsetH) * using.scaleH;
- toRect.right := (fromRect.right + using.offsetH) * using.scaleH;
- toRect.top := (fromRect.top + using.offsetV) * using.scaleV;
- toRect.bottom := (fromRect.bottom + using.offsetV) * using.scaleV
- END; {Transform}
-
-
- {::::::::::::::::: TDepthAndColorChecker :::::::::::::::::::}
-
- PROCEDURE TDepthAndColorChecker.IDepthAndColorChecker (anOffscreenManager: TOffscreenManager);
-
- CONST
- kIdleFreq = 30; { Every 1/2 second }
-
- BEGIN {TDepthAndColorChecker.IDepthAndColorChecker}
- fOffscreenManager := anOffscreenManager;
- SELF.IEvtHandler(NIL);
- SELF.SetIdleFreq(kIdleFreq)
- END; {TDepthAndColorChecker.IDepthAndColorChecker}
-
-
- PROCEDURE TDepthAndColorChecker.Fields (PROCEDURE DoToField (fieldName: Str255;
- fieldAddr: Ptr;
- fieldType: INTEGER));
- OVERRIDE;
-
- BEGIN {TDepthAndColorChecker.Fields}
- DoToField('TDepthAndColorChecker', NIL, bClass);
- DoToField('fOffscreenManager', @fOffscreenManager, bObject);
- INHERITED Fields(DoToField);
- END;{TDepthAndColorChecker.Fields}
-
-
- FUNCTION TDepthAndColorChecker.DoIdle(phase: IdlePhase): BOOLEAN;
- OVERRIDE;
-
- BEGIN {TDepthAndColorChecker.DoIdle}
- fOffscreenManager.CheckDepthAndColor;
- DoIdle := FALSE
- END;{TDepthAndColorChecker.DoIdle}
-
-
- {::::::::::::::::: TOffscreenManager :::::::::::::::::::}
-
- {$S AInit}
- PROCEDURE TOffscreenManager.IOffscreenManager (size: Point);
-
- VAR
-
- aDepthAndColorChecker: TDepthandColorChecker;
- aList: TList;
- port: GrafPtr;
- grayRgn, portRgn: RgnHandle;
- aGDevice: GDHandle;
- anOffscreenDevice: TOffscreenDevice;
-
- BEGIN {TOffscreenManager.IOffscreenManager}
-
- { Initialize the instance variables }
- fDepthAndColorChecker := NIL;
- fDesktopPort := NIL;
- fScreenRect.topLeft := gZeroPt;
- fScreenRect.botRight := size;
-
- fList := NIL;
- NEW(aList);
- FailNIL(aList);
- aList.IList;
-
- {$IFC qDebug}
- aList.SetEltType('TOffscreenDevice');
- {$ENDC}
-
- fList := aLIst;
-
- { Make a GrafPort that encompasses all screens - see Tech Note #194 }
-
- IF colorQD THEN { Color }
- BEGIN
- port := GrafPtr(NewPtr(SIZEOF(CGrafPort)));
- FailNIL(port);
- OpenCPort(CGrafPtr(port))
- END
- ELSE { B&W }
- BEGIN
- port := GrafPtr(NewPtr(SIZEOF(GrafPort)));
- FailNIL(port);
- OpenPort(port)
- END;
-
- grayRgn := GetGrayRgn; { Get the desktop "gray" region. }
- portRgn := NewRgn; { Make the visible region a copy of GrayRgn and its }
- CopyRgn(grayRgn, portRgn); { bounding box the portRect. }
- port^.visRgn := portRgn;
- port^.portRect := portRgn^^.rgnBBox;
- fDesktopPort := GrafPtr(port);
-
- { Create and store in fList an offscreen GDevice for every screen }
-
- IF colorPort(port) THEN { Color }
- BEGIN
- aGDevice := GetDeviceList;
- REPEAT
- NEW(anOffscreenDevice);
- FailNIL(anOffscreenDevice);
- anOffscreenDevice.IOffScreenDevice(port, size, aGDevice);
- fList.Insert(anOffscreenDevice);
- aGDevice := GetNextDevice(aGDevice)
- UNTIL aGDevice = NIL
- END
- ELSE { B&W }
- BEGIN
- NEW(anOffscreenDevice);
- FailNIL(anOffscreenDevice);
- anOffscreenDevice.IOffScreenDevice(GrafPtr(port), size, NIL);
- fList.Insert(anOffscreenDevice);
- END;
-
- { Create and install a cohandler to periodically adjust color and depth. }
-
- NEW(aDepthAndColorChecker);
- FailNIL(aDepthAndColorChecker);
- aDepthAndColorChecker.IDepthAndColorChecker(SELF);
- gApplication.InstallCohandler(aDepthAndColorChecker, TRUE);
- fDepthAndColorChecker := aDepthAndColorChecker;
-
- END; {TOffscreenManager.IOffscreenManager}
-
-
- {$S AInit}
- PROCEDURE TOffscreenManager.Free;
- OVERRIDE;
-
- BEGIN {TOffscreenManager.Free}
-
- { Free associated cohandler }
- IF fDepthAndColorChecker <> NIL THEN
- BEGIN
-
- { Remove from cohandler chain and free. }
-
- gApplication.InstallCohandler(fDepthAndColorChecker, FALSE);
- FreeIfObject(fDepthAndColorChecker);
-
- END;
-
- { Free the grafport representing the desktop. }
- IF fDesktopPort <> NIL THEN
- BEGIN
- ClosePort(fDesktopPort);
- DisposPtr(Ptr(fDesktopPort))
- END;
-
- { Free the list and all its TOffscreenDevices. }
- IF fList <> NIL THEN
- fList.FreeList
-
- END; {TOffscreenManager.Free}
-
-
- {$S AFields}
- PROCEDURE TOffscreenManager.Fields (PROCEDURE DoToField (fieldName: Str255;
- fieldAddr: Ptr;
- fieldType: INTEGER));
- OVERRIDE;
-
- BEGIN {TOffscreenManager.Fields}
- DoToField('TOffscreenManager', NIL, bClass);
- DoToField('fDepthAndColorChecker', @fDepthAndColorChecker, bObject);
- DoToField('fDesktopPort', @fDesktopPort, bGrafPtr);
- DoToField('fScreenRect', @fScreenRect, bRect);
- DoToField('fList', @fList, bObject);
- INHERITED Fields(DoToField);
- END;{TOffscreenManager.Fields}
-
-
- {$S ARes}
- PROCEDURE TOffscreenManager.CheckDepthAndColor;
-
- PROCEDURE CheckEach (item: TOffscreenDevice);
-
- BEGIN {CheckEach}
- item.CheckDepthAndColor
- END; {CheckEach}
-
- BEGIN {TOffscreenManager.CheckDepthAndColor}
- fList.Each(CheckEach)
- END; {TOffscreenManager.CheckDepthAndColor}
-
-
- {$S ADoCommand}
- PROCEDURE TOffscreenManager.Draw (PROCEDURE QuickDrawStuff);
-
- { This procedure takes a procedure as a parameter that has Quickdraw calls and
- executes that procedure in the context of every TOffscreenDevice. The
- TOffscreenDevice can tell whether it needs to do anything by checking to
- see if screenRect intersects it dstRect. }
-
- PROCEDURE DrawEach (item: TOffscreenDevice);
-
- VAR
- screenRect: Rect;
-
- BEGIN {DrawEach}
- screenRect := fScreenRect;
- item.Draw(QuickDrawStuff, screenRect)
- END; {DrawEach}
-
- BEGIN {TOffscreenManager.Draw}
- fList.Each(DrawEach)
- END; {TOffscreenManager.Draw}
-
-
- {$S ADoCommand}
- PROCEDURE TOffscreenManager.CopyBitsFrom (srcBits: BitMap;
- srcRect: Rect;
- offscreenRect: Rect;
- mode: INTEGER;
- maskRgn: RgnHandle);
-
- { Do a CopyBits from srcBits using sectSrcRect to each appropriate TOffscreenDevice.
- A transform is used to map that part of the source that corresponds to the clipped
- portion of the offscreenRect that is in this TOffscreenDevice. That is,
-
- offscreenRect sectScreenRect
- _____________ = ______________
- srcRect sectSrcRect
-
- where offscreenRect, srcRect, and sectScreenRect are given and sectSrcRect
- needs to be calculated using the transformation. }
-
- VAR
- aTransformRect: TransformRect;
-
- PROCEDURE CopyEach (item: TOffscreenDevice);
-
- VAR
- clipRect, sectScreenRect, sectSrcRect: Rect;
-
- BEGIN {CopyEach}
-
- clipRect := item.fClipRect;
-
- { Find the intersection of the offscreenRect and that part of the
- TOffscreenDevice that is used. If they intersect do the CopyBits. }
-
- IF SectRect(clipRect, offscreenRect, sectScreenRect) THEN
- BEGIN
-
- { Calculate sectSrcRect, that part of the source that is
- actually used in the CopyBits. }
-
- Transform(sectScreenRect, aTransformRect, sectSrcRect);
-
- { Do the CopyBits. }
-
- item.CopyBitsFrom(srcBits, sectSrcRect, sectScreenRect, mode, maskRgn)
-
- END
-
- END; {CopyEach}
-
- BEGIN {TOffscreenManager.CopyBitsFrom}
-
- { Create a transform that transforms from the offscreenRect to the srcRect. }
- CalculateTransform(offscreenRect, srcRect, aTransformRect);
-
- { Do a CopyBits for each TOffscreenDevice. }
- fList.Each(CopyEach)
-
- END; {TOffscreenManager.CopyBitsFrom}
-
-
- {$S ADoCommand}
- PROCEDURE TOffscreenManager.CopyBitsFromScreen (screenRect: Rect;
- mode: INTEGER;
- maskRgn: RgnHandle);
-
- { Do a CopyBits from the screen using screenRect as the source
- rectangle to each appropriate TOffscreenDevice. This also
- sets the new fScreenRect to be screenRect, in effect, this
- signals we are "mirroring" a new part of the screen. }
-
- PROCEDURE CopyEach (item: TOffscreenDevice);
-
- VAR
- screenRect: Rect;
-
- BEGIN {CopyEach}
- screenRect := fScreenRect;
- item.CopyBitsFromScreen(screenRect, mode, maskRgn)
- END; {CopyEach}
-
- BEGIN {TOffscreenManager.CopyBitsFromScreen}
- fScreenRect := screenRect; { Signals a mirroring of another area of screen. }
- fList.Each(CopyEach)
- END; {TOffscreenManager.CopyBitsFromScreen}
-
-
- {$S ADoCommand}
- PROCEDURE TOffscreenManager.CopyBitsTo (dstBits: BitMap;
- dstRect: Rect;
- offscreenRect: Rect;
- mode: INTEGER;
- maskRgn: RgnHandle);
-
- { Do a CopyBits from each appropriate TOffscreenDevice to dstBits using sectDstRect.
- A transform is used to map that part of the destination that corresponds to the clipped
- portion of the offscreenRect that is in this TOffscreenDevice. That is,
-
- offscreenRect sectScreenRect
- _____________ = ______________
- dstRect sectDstRect
-
- where offscreenRect, dstRect, and sectScreenRect are given and sectDstRect
- needs to be calculated using the transformation. }
-
- VAR
- aTransformRect: TransformRect;
-
- PROCEDURE CopyEach (item: TOffscreenDevice);
-
- VAR
- clipRect, sectScreenRect, sectDstRect: Rect;
-
- BEGIN {CopyEach}
-
- clipRect := item.fClipRect;
-
- { Find the intersection of the offscreenRect and that part of the
- TOffscreenDevice that is used. If they intersect do the CopyBits. }
-
- IF SectRect(clipRect, offscreenRect, sectScreenRect) THEN
- BEGIN
-
- { Calculate sectDstRect, that part of the destination that is
- actually used in the CopyBits. }
-
- Transform(sectScreenRect, aTransformRect, sectDstRect);
-
- { Do the CopyBits. }
-
- item.CopyBitsTo(dstBits, sectDstRect, sectScreenRect, mode, maskRgn)
-
- END
-
- END; {CopyEach}
-
- BEGIN {TOffscreenManager.CopyBitsTo}
- CalculateTransform(offscreenRect, dstRect, aTransformRect);
- fList.Each(CopyEach)
- END; {TOffscreenManager.CopyBitsTo}
-
-
- {$S ADoCommand}
- PROCEDURE TOffscreenManager.CopyBitsToScreen (mode: INTEGER; maskRgn: RgnHandle);
-
- { Do a CopyBits from each appropriate portion of each TOffscreenDevice
- to the screen using screenRect as the source rectangle. }
-
- PROCEDURE CopyEach (item: TOffscreenDevice);
-
- VAR
- screenRect: Rect;
-
- BEGIN {CopyEach}
- screenRect := fScreenRect;
- item.CopyBitsToScreen(screenRect, mode, maskRgn)
- END; {CopyEach}
-
- BEGIN {TOffscreenManager.CopyBitsToScreen}
- fList.Each(CopyEach)
- END; {TOffscreenManager.CopyBitsToScreen}
-
-
- {::::::::::::::::: TOffscreenDevice ::::::::::::::::::::}
-
- {$S AInit}
- PROCEDURE TOffscreenDevice.IOffscreenDevice (gp: GrafPtr;
- size: Point;
- aScreenDevice: GDHandle);
-
- VAR
-
- grayRgn: RgnHandle;
- screenRect: Rect;
-
- BEGIN {TOffscreenDevice.IOffscreenDevice}
-
- fParentDevice := aScreenDevice;
- IF aScreenDevice <> NIL THEN
- fDeviceRect := aScreenDevice^^.gdPMap^^.bounds
- ELSE
- BEGIN { No GDevices for this machine. }
- grayRgn := GetGrayRgn;
- fDeviceRect := grayRgn^^.rgnBBox
- END;
-
- { Put in the top left of the device, for now. }
- screenRect.topLeft := fDeviceRect.topLeft;
- { And make the clipRect the same size, for now. }
- screenRect.bottom := screenRect.top + size.v;
- screenRect.right := screenRect.left + size.h;
- fClipRect := screenRect;
- INHERITED IOSImage(gp, screenRect)
-
- END; {TOffscreenDevice.IOffscreenDevice}
-
-
- {$S AFields}
- PROCEDURE TOffscreenDevice.Fields (PROCEDURE DoToField (fieldName: Str255;
- fieldAddr: Ptr;
- fieldType: INTEGER));
- OVERRIDE;
-
- BEGIN {TOffscreenDevice.Fields}
- DoToField('TOffscreenDevice', NIL, bClass);
- DoToField('fParentDevice', @fParentDevice, bHandle);
- DoToField('fDeviceRect', @fDeviceRect, bRect);
- DoToField('fClipRect', @fClipRect, bRect);
- INHERITED Fields(DoToField);
- END;{TOffscreenDevice.Fields}
-
-
- {$S ADoCommand}
- PROCEDURE TOffscreenDevice.CheckDepthAndColor;
-
- VAR
-
- savedPort: GrafPtr;
- savedGDevice: GDHandle;
- offset: Point;
- deviceRect: Rect;
- dstRect: Rect;
- ls: BOOLEAN;
- success: BOOLEAN;
-
- BEGIN {TOffscreenDevice.CheckDepthAndColor}
-
-
- { Adjust the coordinate system to reflect a portion of the
- on-screen device in preparation for potential updates.
- That is, make sure that the part of the screen for which
- we are updating is wholly on the device that this object
- is responsible for. }
-
- { Save the current grafEnv and set it to this offscreen }
-
- GetGrafEnv(savedPort, savedGDevice);
- dstRect := fDstRect;
- SetOSGrafEnv(fParent, dstRect, fOSIP);
-
- deviceRect := fDeviceRect;
- SetOrigin(deviceRect.left, deviceRect.top);
-
- offset.h := deviceRect.left - dstRect.left;
- offset.v := deviceRect.top - dstRect.top;
- OffsetRect(dstRect, offset.h, offset.v);
- ClipRect(dstRect);
- fClipRect := dstRect;
- fDstRect := dstRect;
-
- { Restore old port }
-
- SetGrafEnv(savedPort, savedGDevice);
-
- { Adjust the color and depth. }
-
- {$H-}
- ls := SELF.Lock(TRUE);
- IF NOT CorrectDepth(fParent, fDstRect, fOSIP) THEN
- BEGIN
- success := ReallocOSImage(fParent, fDstRect, fOSIP);
-
- {$IFC qDebug}
- IF NOT success THEN
- WRITELN('ReallocOSImage failed in TOffscreenDevice.CheckDepthAndColor');
- {$ENDC}
-
- END;
-
- IF NOT CorrectColor(fParent, fDstRect, fOSIP) THEN
- RecolorOSImage(fParent, fDstRect, fOSIP);
-
- ls := SELF.Lock(ls)
- {$H+}
-
- END; {TOffscreenDevice.CheckDepthAndColor}
-
-
- {$S ADoCommand}
- PROCEDURE TOffscreenDevice.Draw (PROCEDURE QuickDrawStuff; drawRect: Rect);
-
- { After checking to see if drawing needs to be done on this
- TOffscreenDevice, execute QuickDrawStuff (a procedure with
- Quickdraw calls) in its context. }
-
- VAR
-
- dstRect, dummyRect: Rect;
- savedPort: GrafPtr;
- savedGDevice: GDHandle;
-
- BEGIN {TOffscreenDevice.Draw}
-
- { Check to see if this drawing is in our area before
- doing anything. }
-
- dstRect := fDstRect;
- IF SectRect(drawRect, dstRect, dummyRect) THEN
- BEGIN
-
- { Save the current grafEnv and set it to this offscreen }
- GetGrafEnv(savedPort, savedGDevice);
- SetOSGrafEnv(fParent, dstRect, fOSIP);
-
- { Do whatever client wants in our GrafPort }
- QuickDrawStuff;
-
- { Restore old port }
- SetGrafEnv(savedPort, savedGDevice);
-
- END
-
- END; {TOffscreenDevice.Draw}
-
-
- {$S ADoCommand}
- PROCEDURE TOffscreenDevice.CopyBitsFrom (srcBits: BitMap;
- srcRect: Rect;
- offscreenRect: Rect;
- mode: INTEGER;
- maskRgn: RgnHandle);
-
- { CopyBits from srcBits using srcRect to this device using offscreenRect. }
-
- VAR
-
- dstRect: Rect;
- savedPort: GrafPtr;
- savedGDevice: GDHandle;
-
- BEGIN {TOffscreenDevice.CopyBitsFrom}
-
- { Save the current grafEnv and set it to this offscreen }
- GetGrafEnv(savedPort, savedGDevice);
- dstRect := fDstRect;
- SetOSGrafEnv(fParent, dstRect, fOSIP);
-
- { Blast the bits from the screen to the OSImage. }
- CopyBits(srcBits, fOSIp^.portBits, srcRect, offscreenRect, mode, maskRgn);
-
- { Restore old port }
- SetGrafEnv(savedPort, savedGDevice);
-
- END; {TOffscreenDevice.CopyBitsFrom}
-
-
- {$S ADoCommand}
- PROCEDURE TOffscreenDevice.CopyBitsFromScreen (screenRect: Rect;
- mode: INTEGER;
- maskRgn: RgnHandle);
-
- { CopyBits from the screen using the intersection of our device's
- rectangle and screenRect as the source rectangle. Assumes that
- the current port 'thePort' is the desktop. Uses
- TOffscreenDevice.CopyBitsFrom method. }
-
- VAR
-
- savedPort: GrafPtr;
- savedGDevice: GDHandle;
- deviceRect, dstRect, aClipRect: Rect;
- screenSectRect: Rect;
- newDstRect: Rect;
- offset: Point;
-
- {$IFC qDebug}
- aRect: Rect;
- top, left, bottom, right: INTEGER;
- {$ENDC}
-
- BEGIN {TOffscreenDevice.CopyBitsFromScreen}
-
- { screenSectRect is that part of the screenRect that is on our device, ie.,
- the intersection of the screenRect and our own device. }
-
- deviceRect := fDeviceRect;
- IF SectRect(screenRect, deviceRect, screenSectRect) THEN
- BEGIN
-
- { Save the current grafEnv and set it to this offscreen }
-
- GetGrafEnv(savedPort, savedGDevice);
- dstRect := fDstRect;
- SetOSGrafEnv(fParent, dstRect, fOSIP);
-
- { Adjust the coordinate system to properly reflect what portion
- of the screen we're mirroring. }
-
- SetOrigin(screenSectRect.left, screenSectRect.top);
- ClipRect(screenSectRect);
- fClipRect := screenSectRect;
-
- newDstRect := fDstRect;
- offset.h := screenSectRect.left - newDstRect.left;
- offset.v := screenSectRect.top - newDstRect.top;
- OffsetRect(newDstRect, offset.h, offset.v);
- fDstRect := newDstRect;
-
- { Blast the bits from the screen to the OSImage. }
-
- aClipRect := fClipRect;
- SELF.CopyBitsFrom(savedPort^.portBits, screenSectRect, aClipRect, mode, maskRgn);
-
- { Restore old port }
-
- SetGrafEnv(savedPort, savedGDevice);
-
- {$IFC qDebug}
- { Show what's in this offscreen in the lower-right corner of its screen. }
- IF gIntenseDebugging THEN
- BEGIN
- top := fDeviceRect.bottom - (fDstRect.bottom - fDstRect.top);
- left := fDeviceRect.right - (fDstRect.right - fDstRect.left);
- bottom := top + (fClipRect.bottom - fClipRect.top);
- right := left + (fClipRect.right - fClipRect.left);
- SetRect(aRect, left, top, right, bottom);
- CopyBits(fOSIP^.portBits, fParent^.portBits, aClipRect, aRect, mode, maskRgn);
- END;
- {$ENDC}
-
- END
-
- END; {TOffscreenDevice.CopyBitsFromScreen}
-
-
- {$S ADoCommand}
- PROCEDURE TOffscreenDevice.CopyBitsTo (dstBits: BitMap;
- dstRect: Rect;
- offscreenRect: Rect;
- mode: INTEGER;
- maskRgn: RgnHandle);
-
- { CopyBits to dstBits using dstRect from this device using offscreenRect. }
-
- VAR
-
- dstSectRect, srcSectRect: Rect;
- newRect: Rect;
-
- BEGIN {TOffscreenDevice.CopyBitsTo}
-
- { Blast the bits from the screen to the OSImage. }
- CopyBits(fOSIP^.portBits, dstBits, offscreenRect, dstRect, mode, maskRgn);
-
- END; {TOffscreenDevice.CopyBitsTo}
-
-
- {$S ADoCommand}
- PROCEDURE TOffscreenDevice.CopyBitsToScreen (screenRect: Rect;
- mode: INTEGER;
- maskRgn: RgnHandle);
-
- { CopyBits to the screen using the intersection of our device's
- rectangle and screenRect as the destination rectangle. Assumes that
- the current port 'thePort' is the desktop. Uses
- TOffscreenDevice.CopyBitsTo method. }
-
- VAR
-
- deviceRect, clipRect: Rect;
- screenSectRect: Rect;
- currPort: GrafPtr;
-
- BEGIN {TOffscreenDevice.CopyBitsToScreen}
-
- deviceRect := fDeviceRect;
-
- IF SectRect(screenRect, deviceRect, screenSectRect) THEN
- BEGIN
- GetPort(currPort);
-
- { Blast the bits from the OSImage to the screen. }
- clipRect := fClipRect;
- SELF.CopyBitsTo(currPort^.portBits, screenSectRect, clipRect, mode, maskRgn);
- END
-
- END; {TOffscreenDevice.CopyBitsToScreen}